package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CheckInfo;
import com.ruoyi.system.service.ICheckInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入住管理Controller
 * 
 * @author 王帅
 * @date 2024-08-24
 */
@Controller
@RequestMapping("/system/info")
public class CheckInfoController extends BaseController
{
    private String prefix = "system/info";


    @Autowired
    private ICheckInfoService checkInfoService;

    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询入住管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CheckInfo checkInfo)
    {
        startPage();
        List<CheckInfo> list = checkInfoService.selectCheckInfoList(checkInfo);
        return getDataTable(list);
    }

    /**
     * 导出入住管理列表
     */

    @Log(title = "入住管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CheckInfo checkInfo)
    {
        List<CheckInfo> list = checkInfoService.selectCheckInfoList(checkInfo);
        ExcelUtil<CheckInfo> util = new ExcelUtil<CheckInfo>(CheckInfo.class);
        return util.exportExcel(list, "入住管理数据");
    }

    /**
     * 新增入住管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入住管理
     */
    @Log(title = "入住管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CheckInfo checkInfo)
    {
        return toAjax(checkInfoService.insertCheckInfo(checkInfo));
    }

    /**
     * 修改入住管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CheckInfo checkInfo = checkInfoService.selectCheckInfoById(id);
        mmap.put("checkInfo", checkInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存入住管理
     */
    @Log(title = "入住管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CheckInfo checkInfo)
    {
        return toAjax(checkInfoService.updateCheckInfo(checkInfo));
    }

    /**
     * 删除入住管理
     */

    @Log(title = "入住管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(checkInfoService.deleteCheckInfoByIds(ids));
    }
}
